#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: splice03_category_dml.py 
@version:
@time: 2022/03/08 
"""
from TapClientCaseData.ColumnGenerateData.dynamic.splice05_postgres.splice04_sole_dml import *

__all__ = [
    'DML_POSTGRES_ALL_INSERT_1',
    'DML_POSTGRES_ALL_INSERT_2',
    'DML_POSTGRES_ALL_UPDATE'
]


# --------- CATEGORY ---------
def generate_category(args):
    tmp = []
    for i in args:
        tmp.append(str(i))
    return f"{', '.join(tmp)}"


def CATEGORY_INSERT_1(LIST):
    insert0 = ['"pk"']
    insert1 = ['1']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_1')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_INSERT_2(LIST):
    insert0 = ['"pk"']
    insert1 = ['2']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_2')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_UPDATE(LIST):
    TMP = {}
    for ONE in LIST:
        TMP.update(ONE.get('UPDATE'))
    return TMP


#
DML_POSTGRES_NUMERIC_CATEGORY = [
    DML_POSTGRES_SMALLINT,
    DML_POSTGRES_INTEGER,
    DML_POSTGRES_BIGINT,
    DML_POSTGRES_INT2,
    DML_POSTGRES_INT4,
    DML_POSTGRES_INT8,
    DML_POSTGRES_DECIMAL,
    DML_POSTGRES_NUMERIC,
    DML_POSTGRES_REAL,
    DML_POSTGRES_DOUBLE,
    DML_POSTGRES_SMALLSERIAL,
    DML_POSTGRES_SERIAL,
    DML_POSTGRES_BIGSERIAL,
    DML_POSTGRES_MONEY,
    DML_POSTGRES_BOOLEAN
]

DML_POSTGRES_CHAR_CATEGORY = [
    DML_POSTGRES_CHARACTER,
    DML_POSTGRES_VARCHAR,
    DML_POSTGRES_CHARACTER_VARYING,
    DML_POSTGRES_CHAR,
    DML_POSTGRES_TEXT,
]

DML_POSTGRES_TIME_CATEGORY = [
    DML_POSTGRES_TIMESTAMP,
    DML_POSTGRES_TIMESTAMP_WITH_TIME_ZONE,
    DML_POSTGRES_DATE,
    DML_POSTGRES_TIME,
    DML_POSTGRES_TIME_WITH_TIME_ZONE,
    DML_POSTGRES_INTERVAL,
]

DML_POSTGRES_NET_CATEGORY = [
    DML_POSTGRES_CIDR,
    DML_POSTGRES_INET,
    DML_POSTGRES_MACADDR,
    # DML_POSTGRES_MACADDR8
]

DML_POSTGRES_BINARY_CATEGORY = [
    DML_POSTGRES_BYTEA,
    DML_POSTGRES_BIT,
    DML_POSTGRES_BIT_VARYING,
]

DML_POSTGRES_SPECIAL_CATEGORY = [
    DML_POSTGRES_UUID,
    DML_POSTGRES_XML,
    DML_POSTGRES_JSON,
    DML_POSTGRES_JSONB
]

DML_POSTGRES_RANGE_CATEGORY = [
    DML_POSTGRES_ARRAY_ONE,
    DML_POSTGRES_ARRAY_TWO,
    DML_POSTGRES_INT4RANGE,
    DML_POSTGRES_INT8RANGE,
    DML_POSTGRES_NUMRANGE,
    DML_POSTGRES_TSRANGE,
    DML_POSTGRES_TSTZRANGE,
    DML_POSTGRES_DATERANGE
]

DML_POSTGRES_ALL = DML_POSTGRES_NUMERIC_CATEGORY + DML_POSTGRES_CHAR_CATEGORY + DML_POSTGRES_TIME_CATEGORY + \
                   DML_POSTGRES_NET_CATEGORY + DML_POSTGRES_BINARY_CATEGORY + DML_POSTGRES_SPECIAL_CATEGORY + \
                   DML_POSTGRES_RANGE_CATEGORY
DML_POSTGRES_ALL_INSERT_1 = CATEGORY_INSERT_1(DML_POSTGRES_ALL)
DML_POSTGRES_ALL_INSERT_2 = CATEGORY_INSERT_2(DML_POSTGRES_ALL)
DML_POSTGRES_ALL_UPDATE = CATEGORY_UPDATE(DML_POSTGRES_ALL)
